unit rpTSE;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, uClassReport, cxGraphics, cxControls,
  cxLookAndFeels, cxLookAndFeelPainters, cxContainer, cxEdit,
  cxPCdxBarPopupMenu, cxStyles, cxCustomData, cxFilter, cxData, cxDataStorage,
  Data.DB, cxDBData, Vcl.Menus, Data.Win.ADODB, Vcl.ImgList, Vcl.ActnList,
  cxPropertiesStore, Vcl.StdCtrls, cxButtons, cxGridLevel, cxClasses,
  cxGridCustomView, cxGridCustomTableView, cxGridTableView, cxGridDBTableView,
  cxGrid, cxPC, cxGroupBox, cxCheckBox, cxTextEdit, cxMaskEdit, cxDropDownEdit,
  cxCalendar, cxRadioGroup, cxSpinEdit, cxLookupEdit, cxDBLookupEdit,
  cxDBLookupComboBox, cxHeader;

type
  TfmRpTse = class(TfmClassReport)
    Label1: TLabel;
    edBasTarih: TcxDateEdit;
    Label2: TLabel;
    edBitTarih: TcxDateEdit;
    Label3: TLabel;
    Label4: TLabel;
    edSozBitTarih: TcxDateEdit;
    edSozBasTarih: TcxDateEdit;
    RGFirmaTip: TcxRadioGroup;
    seIthFirma: TcxSpinEdit;
    Label5: TLabel;
    lcActionGrupList: TcxLookupComboBox;
    aqActionList: TADOQuery;
    dsActionList: TDataSource;
    Label6: TLabel;
    grdReportnCoKey: TcxGridDBColumn;
    grdReportsFirmaAdi: TcxGridDBColumn;
    grdReportsStatu: TcxGridDBColumn;
    grdReportsFirmaAdres: TcxGridDBColumn;
    grdReportsTelefon: TcxGridDBColumn;
    grdReportsFax: TcxGridDBColumn;
    grdReportsEmail: TcxGridDBColumn;
    grdReportsBelgeNo: TcxGridDBColumn;
    grdReportsBelgeVYer: TcxGridDBColumn;
    grdReportsFirmaIL: TcxGridDBColumn;
    grdReportsHYeriAdresi: TcxGridDBColumn;
    grdReportBelgeNo2: TcxGridDBColumn;
    grdReportdteBelgeTarih: TcxGridDBColumn;
    grdReportsAciklama: TcxGridDBColumn;
    grdReportsYetServisAciklama: TcxGridDBColumn;
    grdReportdteSozTarih: TcxGridDBColumn;
    grdReportsMarka: TcxGridDBColumn;
    grdReportsActionGrup: TcxGridDBColumn;
    Label7: TLabel;
    Label8: TLabel;
    edYTS: TcxTextEdit;
    edAnaFirma: TcxTextEdit;
    grdReportsFirmaILCE: TcxGridDBColumn;
    aqTseNo: TADOQuery;
    dsTseNo: TDataSource;
    Label9: TLabel;
    lcTseNo: TcxLookupComboBox;
    grdReportBolge: TcxGridDBColumn;
    procedure acListExecute(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  fmRpTse: TfmRpTse;

implementation

uses Data;

{$R *.dfm}

procedure TfmRpTse.acListExecute(Sender: TObject);
var
  ExCursor: TCursor;
begin
  inherited;
  ExCursor := Screen.Cursor;
  Screen.Cursor := crSQLWait;
  try
    with aqList do
    begin
      Close;
      SQL.Text := 'EXEC SP_TSE @BasTarih=:BasTarih,@BitTarih=:BitTarih,@ActionGrup=:ActionGrup,@SozBasTarih=:SozBasTarih,@SozBitTarih=:SozBitTarih,@IthFirmaSay=:IthFirmaSay,@YTS=:YTS,@AnaFirma=:AnaFirma,@Markali=:Markali,@TseNo=:TseNo';

      if (edBasTarih.Text = '') and (edBitTarih.Text = '') then
      begin
        Parameters.ParamByName('BasTarih').Value := NULL;
        Parameters.ParamByName('BitTarih').Value := NULL;
      end
      else
      begin
        Parameters.ParamByName('BasTarih').Value := edBasTarih.Date;
        Parameters.ParamByName('BitTarih').Value := edBitTarih.Date;
      end;

      if Trim(lcActionGrupList.Text) = '' then
        Parameters.ParamByName('ActionGrup').Value := NULL
      else
        Parameters.ParamByName('ActionGrup').Value := lcActionGrupList.EditValue;

      if (edSozBasTarih.Text = '') and (edSozBitTarih.Text = '') then
      begin
        Parameters.ParamByName('SozBasTarih').Value := NULL;
        Parameters.ParamByName('SozBitTarih').Value := NULL;
      end
      else
      begin
        Parameters.ParamByName('SozBasTarih').Value := edSozBasTarih.Date;
        Parameters.ParamByName('SozBitTarih').Value := edSozBitTarih.Date;
      end;

      Parameters.ParamByName('IthFirmaSay').Value := seIthFirma.Value;

      Parameters.ParamByName('YTS').Value := edYTS.Text;
      Parameters.ParamByName('AnaFirma').Value := edAnaFirma.Text;
      Parameters.ParamByName('Markali').Value := (RGFirmaTip.EditValue = 2);
      Parameters.ParamByName('TseNo').Value := lcTseNo.EditValue;
      Open;
    end;
  finally
    Screen.Cursor := ExCursor;
  end;
  // grdReport.DataController.CreateAllItems(True);
  // grdReport.ApplyBestFit();
end;

procedure TfmRpTse.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  inherited;
  Action := caFree;
  fmRpTse := nil;
end;

procedure TfmRpTse.FormCreate(Sender: TObject);
begin
  inherited;
  RGFirmaTip.EditValue := 2;

  aqActionList.Close;
  aqActionList.Open;

  aqTseNo.Close;
  aqTseNo.Open;
end;

end.
